<?php

class Kzend_Mail extends Zend_Mail
{
    /**
     * Public constructor
     *
     * @param string $charset
     */
    public function __construct($charset = 'UTF-8')
    {
        parent::__construct($charset);

        $config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/application.ini", APPLICATION_ENV);

        //        $this->_mail = new Kzend_Mail();
        $this->setDefaultTransport(new Zend_Mail_Transport_Smtp($config->mail->smtp));
        $this->setFrom($config->mail->default->from);

        $aryTo = explode(',', $config->mail->default->to);
        foreach ($aryTo as $key => $to) {
            $this->addTo($to);
        }
        $this->initView();
    }

    /**
     * Initialize View object
     *
     * @return void
     */
    protected function initView()
    {
        $this->_view = new Zend_View(array(
                'basePath' => APPLICATION_PATH));
    }

    /**
     * Sets the subject of the message
     *
     * @param   string    $subject
     * @return  Zend_Mail Provides fluent interface
     * @throws  Zend_Mail_Exception
     */
    public function setSubject($subject)
    {
        return parent::setSubject(mb_convert_encoding($subject, 'UTF-8', 'UTF-8'));
    }

    /**
     * Sets the text body for the message.
     *
     * @param  string $txt
     * @param  string $charset
     * @param  string $encoding
     * @return Zend_Mail Provides fluent interface
     */
    public function setBodyText($txt, $charset = 'UTF-8', $encoding = Zend_Mime::ENCODING_BASE64)
    {
        return parent::setBodyText(mb_convert_encoding($txt, $charset, 'UTF-8'), $charset, $encoding);
    }
}
